"use strict";
(function (Vue, Mescroll, axios, undefined) {
    
    new Vue({
        el: '#app',
		delimiters: ['[', ']'],
        data: {
            message: '123',
            goods: [],
            mescroll: null,
            page: {
                num: 1,
                size: 3
            }
        },
        methods: {
            getData: function (pageNum, pageSize, callback, errCallback) {
                setTimeout(function () {
                    var data = goods;
                    var dataList = [];
                    for (var i = (pageNum - 1) * pageSize; i < pageNum * pageSize; i++) {
                        if (i == data.length)
                            break;
                        dataList.push(data[i]);
                    }
                    callback && callback(dataList);
                }, 500);
            },
            upCallback: function (page) {
                var self = this;
                // 去获取数据page会自动增加数值
                this.getData(page.num, page.size, function (curPageData) {
                    // 如果为第一页则清空防止重复增加数据
                    page.num == 1 && (self.goods = []);
                    // 更新数据列表
                    self.goods = self.goods.concat(curPageData);
                    // 显示请求
                    console.log("page.num=" + page.num + ", page.size=" + page.size + ", curPageData.length=" + curPageData.length +
                        ", self.goods.length==" + self.goods.length);
                    // 如果返回的数据没有更多则显示提示
                    self.mescroll.endSuccess(curPageData.length);
                }, function () {
                    self.mescroll.endErr();
                });
            }
        },
        mounted: function () {
            var self = this;
            self.mescroll = new Mescroll("mescroll", {
                down: {
                    isLock: true,
                },
                up: {
                    // auto: false,
                    callback: self.upCallback,
                    page: {
                        size: 4
                    }
                }
            });
        }
    });
}(Vue, MeScroll, axios));
